package com.atfusu.controller;

import com.atfusu.bean.entity.UserInfo;
import com.atfusu.bean.vo.UserFollowVo;
import com.atfusu.result.Result;
import com.atfusu.service.UserFollowService;
import com.atfusu.service.UserInfoService;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * Title:
 * Author: fusu
 * DateTime:  2022/12/3
 * Description:
 **/
@Controller
@RequestMapping("/userFollow")
@ResponseBody
public class UserFollowController {

    @DubboReference
    private UserInfoService userInfoService;

    @DubboReference
    private UserFollowService userFollowService;


    @RequestMapping("/auth/follow/{houseId}")
    public Result follow(@PathVariable Long houseId, HttpSession session) {
        //将关注添加到数据库
        UserInfo userInfo = (UserInfo) session.getAttribute("userInfo");
        userFollowService.follow(houseId, userInfo.getId());
        return Result.ok();
    }

    @RequestMapping("/auth/list/{pageNum}/{pageSize}")
    public Result list(@PathVariable Integer pageNum, @PathVariable Integer pageSize, HttpSession session) {
        UserInfo userInfo = (UserInfo) session.getAttribute("userInfo");
        PageInfo<UserFollowVo> listPage = userFollowService.findListPage(pageNum, pageSize, userInfo.getId());

        return Result.ok(listPage);
    }

    @RequestMapping("/auth/cancelFollow/{id}")
    public Result cancelFollow(@PathVariable Long id) {
       userFollowService.delete(id);

        return Result.ok();
    }
}
